package com.example.qxfw.hbqx.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.entity.qx.*;
import com.example.qxfw.common.entity.xt.YbzzConfig;
import com.example.qxfw.common.entity.zy.AirHazeWarn;
import com.example.qxfw.common.util.DateUtil;
import com.example.qxfw.hbqx.service.QxybcpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Date;
import java.util.List;

@ApiIgnore
@Api(tags = "环保气象-气象预报产品")
@RestController
@CrossOrigin
@RequestMapping("/qxybcp")
public class QxybcpController {

    @Autowired
    private QxybcpService qxybcpService;

    @ApiOperation("通过要素类型查询预报制作参数")
    @GetMapping(value = "/selectByElementTypeOfYbzzConfig")
    public SysResult selectByElementTypeOfYbzzConfig(String elementtype){
        List<YbzzConfig> list = qxybcpService.selectByElementTypeOfYbzzConfig(elementtype);
        return SysResult.success(list);
    }

    @ApiOperation("通过站点名称查询所有乡镇预报站点")
    @GetMapping(value = "/selectByStationNameOfTownshipStation")
    public SysResult selectByStationNameOfTownshipStation(String stationname){
        List<TownshipStation> list = qxybcpService.selectByStationNameOfTownshipStation(stationname);
        return SysResult.success(list);
    }

    @ApiOperation("根据站点类型查询所有站点名称和站点id")
    @GetMapping(value = "/selectByFlagOfSpecialSrvStation")
    public SysResult selectByFlagOfSpecialSrvStation(String flag){
        List<SpecialSrvStation> list = qxybcpService.selectByFlagOfSpecialSrvStation(flag);
        return SysResult.success(list);
    }

    @ApiOperation("根据观测时间查询高空预报")
    @GetMapping(value = "/selectByObservTimeOfHighElements")
    public SysResult selectByObservTimeOfHighElements(String date){
        Date observtime = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(date));
        List<HighElements> list = qxybcpService.selectByObservTimeOfHighElements(observtime);
        return SysResult.success(list);
    }

    @ApiOperation("根据观测时间查询地面要素温度，站点名称和id")
    @GetMapping(value = "/selectByObservtimeOfGroundElements")
    public SysResult selectByObservtimeOfGroundElements(String date){
        Date observtime = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(date));
        List<GroundElements> list = qxybcpService.selectByObservtimeOfGroundElements(observtime);
        return SysResult.success(list);
    }

    @ApiOperation("根据预报日期类型时次查询逆温预报")
    @GetMapping(value = "/selectByDatecharAndTimecharAndFcsttypeOfTempInversionyb")
    public SysResult selectByDatecharAndTimecharAndFcsttypeOfTempInversionyb(String date, String time, String fcsttype){
        Date datechar = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(date));
        Date timechar = DateUtil.localDateTimeToTimestamp(DateUtil.stringToLocalDateTime(time));
        List<TempInversionyb> list = qxybcpService.selectByDatecharAndTimecharAndFcsttypeOfTempInversionyb(datechar, timechar, fcsttype);
        return SysResult.success(list);
    }

    @ApiOperation("根据日期段查询霾预报产品")
    @GetMapping(value = "/selectByDateCharOfAirHazeWarn")
    public SysResult selectByDateCharOfAirHazeWarn(String dateStart, String dateEnd){
        Date datecharStart = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(dateStart));
        Date datecharEnd = DateUtil.localDateTimeToTimestamp(DateUtil.stringToLocalDateTime(dateEnd));
        List<AirHazeWarn> list = qxybcpService.selectByDateCharOfAirHazeWarn(datecharStart, datecharEnd);
        return SysResult.success(list);
    }

    @ApiOperation("根据日期和站点id删除能见度预报")
    @DeleteMapping(value = "/deleteByDateCharAndStationIdOfHazeVisibilityForecast")
    public SysResult deleteByDateCharAndStationIdOfHazeVisibilityForecast (String date, String stationid){
        Date datechar = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(date));
        int result = qxybcpService.deleteByDateCharAndStationIdOfHazeVisibilityForecast(datechar, stationid);
        return SysResult.success(result);
    }

    @ApiOperation("根据日期和站点id删除能见度预报")
    @PostMapping(value = "/insertByStationIDAndStationNameAndDateCharAndNTimesAndHazeVisibilityOfHazeVisibilityForecast")
    public SysResult insertByStationIDAndStationNameAndDateCharAndNTimesAndHazeVisibilityOfHazeVisibilityForecast
            (String stationid, String stationname, String date, String times, Double hazevisibility){
        Date datechar = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(date));
        Date ntimes = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(times));
        int result = qxybcpService.insertByStationIDAndStationNameAndDateCharAndNTimesAndHazeVisibilityOfHazeVisibilityForecast(
                stationid, stationname, datechar, ntimes, hazevisibility
        );
        return SysResult.success(result);
    }

    @ApiOperation("根据时间段和站点查询能见度报表时期，时效，能见度")
    @GetMapping(value = "/selectByIdAndTimeframeOfHVF")
    public SysResult selectByIdAndTimeframeOfHVF(String stationid, String dateStart, String dateEnd){
        Date datecharStart = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(dateStart));
        Date datecharEnd = DateUtil.localDateTimeToTimestamp(DateUtil.stringToLocalDateTime(dateEnd));
        List<HazeVisibilityForecast> list = qxybcpService.selectByIdAndTimeframeOfHVF(stationid, datecharStart, datecharEnd);
        return SysResult.success(list);
    }

    @ApiOperation("通过站点id和日期查询能见度预报")
    @GetMapping(value = "/selectByIdAndTimeOfHazeVisibilityForecast")
    public SysResult selectByIdAndTimeOfHazeVisibilityForecast(String stationid, String date){
        Date datechar = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(date));
        List<HazeVisibilityForecast> list = qxybcpService.selectByIdAndTimeOfHazeVisibilityForecast(stationid, datechar);
        return SysResult.success(list);
    }

    @ApiOperation("根据日期时效时次站点id查询乡镇预报临时表")
    @GetMapping(value = "/selectByIdNtimesDatecharTimechar")
    public SysResult selectByIdNtimesDatecharTimechar(String date, Integer ntimes, String timechar, String stationid){
        Date datechar = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(date));
        List<TownShipForecastTemp> list = qxybcpService.selectByIdNtimesDatecharTimechar(datechar, ntimes, timechar, stationid);
        return SysResult.success(list);
    }

    @ApiOperation("根据日期类型和时次查询混合层高度")
    @GetMapping(value = "/selectByDateAndTypeAndTimesOfMixingHeight")
    public SysResult selectByDateAndTypeAndTimesOfMixingHeight(String date, Integer forecasttype, Integer ntimes){
        Date datechar = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(date));
        List<MixingHeight> list = qxybcpService.selectByDateAndTypeAndTimesOfMixingHeight(datechar, forecasttype, ntimes);
        return SysResult.success(list);
    }

    @ApiOperation("根据日期和时次查询逆温实况表")
    @GetMapping(value = "/selectByDateAndTimeOfTempInversion")
    public SysResult selectByDateAndTimeOfTempInversion(String date, String tiemchar){
        Date datechar = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(date));
        List<TempInversion> list = qxybcpService.selectByDateAndTimeOfTempInversion(datechar, tiemchar);
        return SysResult.success(list);
    }

    @ApiOperation("根据时间段获取能见度预报信息")
    @GetMapping(value = "/selectByTimePeriodOfHazeVisibilityForecast")
    public SysResult selectByTimePeriodOfHazeVisibilityForecast(String dateStart, String dateEnd){
        Date datecharStart = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(dateStart));
        Date datecharEnd = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(dateEnd));
        List<HazeVisibilityForecast> list = qxybcpService.selectByTimePeriodOfHazeVisibilityForecast(datecharStart, datecharEnd);
        return SysResult.success(list);
    }

    @ApiOperation("根据时间点获取能见度预报信息")
    @GetMapping(value = "/selectByTimeOfHazeVisibilityForecast")
    public SysResult selectByTimeOfHazeVisibilityForecast(String date){
        Date datechar = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(date));
        List<HazeVisibilityForecast> list = qxybcpService.selectByTimeOfHazeVisibilityForecast(datechar);
        return SysResult.success(list);
    }

    @ApiOperation("获取所有乡镇预报主表信息")
    @GetMapping(value = "getAllOfTownshipForecast")
    public SysResult getAllOfTownshipForecast(){
        List<TownshipForecast> list = qxybcpService.getAllOfTownshipForecast();
        return SysResult.success(list);
    }

    @ApiOperation("根据日期时次时效站点名字获取气象要素信息")
    @GetMapping(value = "selectByDateTimecharNtimesNameOfTownshipForecast")
    public SysResult selectByDateTimecharNtimesNameOfTownshipForecast(
            String date, String timechar, Integer ntimes, String stationname){
        Date datechar = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(date));
        List<TownshipForecast> list = qxybcpService.selectByDateTimecharNtimesNameOfTownshipForecast(
                datechar, timechar, ntimes, stationname);
        return SysResult.success(list);
    }




}
